<?php
/**
 * The Pagination class
 */
abstract class Pagination
{
	/**
	 * Generate the pagination array
	 * 
	 * @param array $args 
	 * @return array
	 */
	static public function generate($args)
	{
		$paginationArray = array();
		$args['page_size'] = isset($args['page_size']) ? $args['page_size'] : 10;
		$pageTotal = ceil($args['item_total'] / $args['page_size']);
		$displayPages = isset($args['display_pages']) ? $args['display_pages'] : 5;
		if (0 < $pageTotal)
		{
			$currentPage = $args['current_page'];
			if (1 < $currentPage)
			{
				$paginationArray["previous_page"] = $currentPage - 1;
			}
			if ($pageTotal > $currentPage)
			{
				$paginationArray["next_page"] = $currentPage + 1;
			}
			if ($pageTotal > $displayPages)
			{
				$firstPage = max($currentPage - floor($displayPages / 2), 1);
				$firstPage = min($firstPage, $pageTotal - $displayPages + 1);
				$lastPage = $firstPage + $displayPages - 1;
			}
			else
			{
				$firstPage = 1;
				$lastPage = $pageTotal;
			}
			$paginationArray["first_page"] = $firstPage;
			$paginationArray["last_page"] = $lastPage;
			for ($i = $firstPage; $i <= $lastPage; $i++)
			{
				$paginationArray[$i] = $i;
			}
		}
		return $paginationArray;
	}
}
